package com.sieaf.bpo;

import java.sql.Connection;
import java.util.HashMap;
import javax.transaction.UserTransaction;
import com.util.DBUtil;
import com.sieaf.config.ConstantValue;
import com.sieaf.exception.AppException;

public class BaseService {
	
	protected UserTransaction transaction = null;
	protected Connection conn = null;
//	protected DBUtil  dbUtil;

	
	
	
	protected Connection getConnection()throws AppException
	 {
//	  transaction = DBUtil.getUserTransaction();
	   return  DBUtil.getConnection();
	 }
	protected void close() {
	 try{
		if (conn != null) {
			conn.close();
		}
		}catch(Exception e){
			e.printStackTrace();
		}
		  conn = null;
	  }

	protected void commit() {
		try{
		if (conn != null) {
			conn.commit();
		}	
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	protected void rollback() {
	try{
		if (conn != null) {
			conn.rollback();
		}		
	   }catch(Exception e){
		e.printStackTrace();
	}
	}	
	/**�������ת��
	 *
	 * @param o
	 * @return
	 */
	public String ObjectToString(Object o) {
		String ret = "";
		if (o == null) {
			ret = "";
		} else {
			ret = o.toString();
		}
		return ret;
	}

	public HashMap delNullValue(HashMap inhm) //ɾ��HashMap�йؼ���Ϊnull����Ϊ""ֵ�Ĺؼ���
	{
		HashMap hm = new HashMap();
		java.util.Set set = inhm.entrySet();
		java.util.Iterator i = set.iterator();
		while (i.hasNext()) {
			java.util.Map.Entry me = (java.util.Map.Entry) i.next();
			if (null != (String) me.getValue() && !"".equals(me.getValue().toString().trim())) //���Ϊnull���� ��Ϊ""ֵ
			{
				hm.put(me.getKey().toString().toUpperCase(), me.getValue());
			}
		}
		return hm;
	}
       /*
	    * ��ʽ
	    * */
	 public void Debug(String s)
	 {
			//if(ConstantValue.getDebug()==null||"1".equals(ConstantValue.getDebug()))
				System.out.println(s);
	 }
}